<?php
/*:::::::::::::::::: BASE DE DATOS :::::::::::::::*/
 //FUNCTIONS FOR DB OPERATIONS
	/*
	* Name: connectBD
	* @params none
	* Return BD link indetifier
	* description: Performs the DataBase Server Connection and selection
	*/
	function connectDB() {
		//PDO connection
		try {
			$db = new PDO('mysql:host=localhost;dbname=RV1960_Shalom;charset=utf8', 'root', '');	
			//$db = new PDO('mysql:host=localhost;dbname=alertosoccer;charset=utf8', 'root', '');	
			return $db ;
		}
		catch(PDOException $e) {
	    	/*** echo the error message ***/
	    	//echo $e->getMessage() . 'Problem Connecting to Database ... Please try later';
			exit;
	    }
	}

	/* Name: getPaisBD
	 * @params string $v_pais
	 * Return fetch
	 * description: Consulta si exite dato en la tabla
	 */
	function getPaisBD($v_pais) {
		//echo "SELECT * FROM e_paises WHERE v_pais = $v_pais";
		$db = connectDB();
		$queryStmt = $db->prepare('SELECT i_idpais FROM e_paises WHERE v_pais = :v_pais');
		$queryStmt->bindParam(':v_pais', $v_pais, PDO::PARAM_STR, 250); //Automatically sanitized by PDO
		$queryStmt->execute();
		$db = null; //Close DB Connection
		return ($queryStmt->fetch());
	}

	/* Name: addLibroCapVer
	 * @params $i_idlibro, $i_cap, $i_ver, $t_ver
	 * Return fetch
	 * description: Inserta datos en la tabla
	 */
	function addLibroCapVer($i_idlibro, $i_cap, $i_ver, $t_ver) {
		//echo "INSERT INTO e_predictions (i_iduser, i_idpartido, prediction, d_fecha) VALUES ($i_iduser, $i_idpartido, $i_statusprediction, $d_fecha)";
		$db = connectDB();
		$queryStmt = $db->prepare('INSERT INTO e_libros_cap_ver (i_idlibro, i_cap, i_ver, t_ver) VALUES (:i_idlibro, :i_cap, :i_ver, :t_ver)');
		$queryStmt->bindParam(':i_idlibro', $i_idlibro, PDO::PARAM_INT, 2); //Automatically sanitized by PDO
		$queryStmt->bindParam(':i_cap', $i_cap, PDO::PARAM_INT, 3); //Automatically sanitized by PDO
		$queryStmt->bindParam(':i_ver', $i_ver, PDO::PARAM_INT, 3); //Automatically sanitized by PDO
		$queryStmt->bindParam(':t_ver', $t_ver, PDO::PARAM_STR); //Automatically sanitized by PDO
		$queryStmt->execute();
		$db = null; //Close DB Connection
		return ($queryStmt->rowCount());
	}

?>